package org.test4j.mock.processor;

import com.google.auto.service.AutoService;
import org.test4j.mock.Mocks;
import org.test4j.mock.processor.filer.MocksAttribute;
import org.test4j.mock.processor.filer.MocksFiler;
import org.test4j.mock.processor.filer.StubsBeanFiler;

import javax.annotation.processing.Processor;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import java.util.List;

@AutoService(Processor.class)
@SupportedSourceVersion(SourceVersion.RELEASE_8)
@SupportedAnnotationTypes("org.test4j.mock.Mocks")
public class MockProcessor extends BaseProcessor<Mocks> {

    @Override
    protected Class<Mocks> getAnnotationClass() {
        return Mocks.class;
    }

    @Override
    protected void doProcessor(Element element, Mocks mocks) {
        String fullName = ((TypeElement) element).getQualifiedName().toString();
        List<String> classes = MocksAttribute.getClasses((TypeElement) element);
        new MocksFiler(fullName, mocks.suffixMocks(), classes).writeFiler();
        if (mocks.fakeBean()) {
            new StubsBeanFiler(fullName, mocks.suffixConfiguration(), classes).writeFiler();
        }
    }
}